<?
session_start();
include_once("database.php");
include_once("backend.php");
include_once("login_management.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Scouting.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<?
if(isset($_GET['team']))
	{
		$title="Data for team " . $_GET['team'];
	}
	else if(isset($_GET['match']))
	{
		$title="Data for match " . $_GET['match'];
	}
	else if(isset($_GET['repeatheaders']))
	{
		$title="All Data";
	}
	else if(isset($_GET['chartlimit']))
	{
		$title="View Charts";
	}
	else if(isset($_GET['predictor']))
	{
		$title="Match Predictor Results";
	}
	else
	{
		$title = "View";
	}
?>
<title><?  echo $title; ?> | Team Spyder Scouting</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="scouting.css"/>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
<div class="main">
<div class="top"><l>
<a class="navigation" href="./index.php">Home</a> | 
<a class="navigation" href="./input.php">Input Data</a> | 
<a class="navigation" href="./view.php">View Data</a> | 
<a class="navigation" href="./edit.php">Edit Data</a> | 
<a class="navigation" href="./predict.php">Match Predictor</a> | 
<script type="text/javascript">
function LoadLogin()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("content").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","login.php",true);
xmlhttp.send();
}
</script>
<?
if($logged_in)
{
	echo "<l> Welcome, " . $_SESSION['username'] . " </l>";
	echo "<a class=\"navigation\" href=\"./logout.php\">Log out</a>\n";
}
else
{
	echo "<l> You are not logged in. </l>";
	echo "<a class=\"navigation\" href=\"#\" onclick=\"LoadLogin()\">Log in</a>\n";
}

?>
</l>
</div>
<div id="content" class="content"><!-- InstanceBeginEditable name="Content" -->
<?
if($logged_in)
{
	if(isset($_GET['team']))
	{
		DisplayTeam($_GET['team']);
	}
	else if(isset($_GET['match']))
	{
		DisplayMatch($_GET['match']);
	}
	else if(isset($_GET['repeatheaders']))
	{
		DisplayAll($_GET['repeatheaders']);
	}
	else if(isset($_GET['srmax']))
	{
		DisplaySpyderRank($_GET['srmax']);
	}
	else if(isset($_GET['chartlimit']))
	{
		DisplayCharts($_GET['chartlimit']);
	}
	else if(isset($_GET['predictor']))
	{
		$numteams=GetNumTeamsMatch();
		for($i=1;$i<=$numteams;$i++)
		{
			$competitors[$i]=$_GET['competitor_'.$i];
		}
		PredictMatch($competitors);
	}
	else
	{
		?>
        <h1>View Data</h1>
        <table>
        <tr>
        <td></td>
        <td>
        <input type="button" value="View All!" onclick="parent.location='view.php?repeatheaders=1'" />
        </td>
        </tr>
        <form action="view.php" method="get">
        <tr>
        <td>
        <input type="text" name="team" />
        </td>
        <td>
        <input type="submit" value="View Team!" />
        </td>
        </tr>
        </form>
        <form action="view.php" method="get">
        <tr>
        <td>
        <input type="text" name="match" />
        </td>
        <td>
        <input type="submit" value="View match!" />
        </td>
        </tr>
        </form>
        <tr>
        <td>
        </td>
        <td>
        <input type="button" value="View SpyderRank!" onclick="parent.location='view.php?srmax=32'" />
        </td>
        </tr>
        <tr>
        <td>
        </td>
        <td>
        <input type="button" value="View Charts" onclick="parent.location='view.php?chartlimit=32'" />
        </td>
        </tr>
        </table>
        
        <?
	}
	mysql_close();
}
else
{
	displayLogin();
	mysql_close();
}
?><!-- InstanceEndEditable -->
</div>
</div>

</body>
<!-- InstanceEnd --></html>
